function error_value = process_error_p_2d(mesh, pde, U, error_type)
switch error_type
    case "Linf"
        err_E = 0;
        for n = 1:mesh.Ne
            E = mesh.node(mesh.elem(n,:),:);
            V = E(1:3,:);
            [gauss_points_loc, ~] = gauss_lengdre_loc(V, "2d");
            phi = basis_function_loc(V, gauss_points_loc(:,1), gauss_points_loc(:,2), "P1");
            ph_E = zeros(9,1);
            for i = 1:3
                ph_E = ph_E + U(mesh.elem(n,i)+2*mesh.Nb) .* phi{i};
            end
            f = max(abs(pde.p(gauss_points_loc(:,1),gauss_points_loc(:,2)) - ph_E));
            if f > err_E
                err_E = f;
            end
        end
        error_value = err_E;
    case "L2"
        err_E = 0;
        for n = 1:mesh.Ne
            E = mesh.node(mesh.elem(n,:),:);
            V = E(1:3,:);
            [gauss_points_loc, gauss_weights_loc] = gauss_lengdre_loc(V, "2d");
            phi = basis_function_loc(V, gauss_points_loc(:,1), gauss_points_loc(:,2), "P1");
            ph_E = zeros(9,1);
            for i = 1:3
                ph_E = ph_E + U(mesh.elem(n,i)+2*mesh.Nb) .* phi{i};
            end
            f = (pde.p(gauss_points_loc(:,1),gauss_points_loc(:,2)) - ph_E).^2;
            r = gauss_weights_loc * f;
            err_E = err_E + r;
        end
        error_value = sqrt(err_E);
    case "H1"
        err_Ex = 0;
        err_Ey = 0;
        for n = 1:mesh.Ne
            E = mesh.node(mesh.elem(n,:),:);
            V = E(1:3,:);
            [gauss_points_loc, gauss_weights_loc] = gauss_lengdre_loc(V, "2d");
            phix = basis_function_loc(V, gauss_points_loc(:,1), gauss_points_loc(:,2), "P1", "dx");
            phiy = basis_function_loc(V, gauss_points_loc(:,1), gauss_points_loc(:,2), "P1", "dy");
            ph_Ex = zeros(9,1);
            ph_Ey = zeros(9,1);
            for i = 1:3
                ph_Ex = ph_Ex + U(mesh.elem(n,i)+2*mesh.Nb) .* phix{i};
                ph_Ey = ph_Ey + U(mesh.elem(n,i)+2*mesh.Nb) .* phiy{i};
            end
            f1 = (pde.pdx(gauss_points_loc(:,1),gauss_points_loc(:,2)) - ph_Ex).^2;
            f2 = (pde.pdy(gauss_points_loc(:,1),gauss_points_loc(:,2)) - ph_Ey).^2;
            rx = gauss_weights_loc * f1;
            ry = gauss_weights_loc * f2;
            err_Ex = err_Ex + rx;
            err_Ey = err_Ey + ry;
        end
        error_value = sqrt(err_Ex + err_Ey);
    otherwise
        error("Invalid error type.");
end
end